(function(app) {
    app
        .controller("charge_feeCtrl", ["$scope", "$rootScope", "myFactory", '$http', '$stateParams', '$state', '$ionicHistory', '$ionicScrollDelegate', function($scope, $rootScope, myFactory, $http, $stateParams, $state, $ionicHistory, $ionicScrollDelegate) {
            //参数接收、定义
            var chdrnum01 = $stateParams.chdrnum01;
            var chdrcoy = $stateParams.chdrcoy;
            var pageData = $stateParams.pageData;
            var itemCommonList = $stateParams.itemCommonList;
            var strItemIds = $stateParams.strItemIds;
            var pclist = pageData.pclist; //银行列表
            var pclistBack = []; //银行列表，用于JS校验
            var citylist = pageData.citylist; //城市列表
            var beneFlag = false; //账户持有人那里显示权益人的标志，false为不显示
            var user = pageData.user;
			//S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 start
            var isSamePerson = $stateParams.isSamePerson;
			//S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 end
            var userType = ""; //	用户类型
            var token = sessionStorage.getItem("token");
            /*********** 《S2019091010023 移动保全限制湖南分公司使用被保人账号进行保全缴费系统需求》 add by huanghaokun 20190923 start***********/
            var hunan = pageData.hunan; //是否湖南保单
            var insurant = pageData.insurant; //续期账户是否为被保人账号
            var insurantFir = pageData.insurantFir; //首期账户是否为被保人账号
            /*********** 《S2019091010023 移动保全限制湖南分公司使用被保人账号进行保全缴费系统需求》 add by huanghaokun 20190923 end***********/

            //绑定信息到页面
            $scope.itemId = pageData.itemId;
            $scope.chdrnum01 = $stateParams.chdrnum01;
            $scope.pageData = $stateParams.pageData;
            $scope.itemList = pageData.itemList;
            $scope.fmtShowTitle = pageData.fmtShowTitle;
            $scope.charge = pageData.charge;
            $scope.account = pageData.account; //续期账户
            $scope.accountFir = pageData.accountFir; //首期缴费账户
            $scope.hbFlag = false; //默认以平常方式统计金额
            $scope.yjFlag = false; //收费时才显示溢缴保费金额信息，平时默认不显示
            $scope.giveRight1 = false; //用于控制续期账户详细信息，显示隐藏部分，默认隐藏
            $scope.giveRight2 = false; //用于控制授权其他用户详细信息，显示隐藏部分，默认隐藏
            $scope.giveRight3 = false; //用于控制首期缴费账户详细信息，显示隐藏部分，默认隐藏
            $scope.divAccountFlag = true; //用于显示选择退款授权模块，当为false时候表示隐藏，默认显示
            $scope.policy = pageData.policy; //获得缓存保单
            $scope.policyData = pageData.policy; //用于保单相应的，那边用的名字为policyData
            $scope.policyData.ptdate01 = myFactory.DateTools($scope.policyData.ptdate01);
            $scope.readFlag = false; //阅读协议标志，默认为false

            $scope.Type = $scope.charge.type;
            $scope.ReceiptAmount = $scope.charge.receiptAmount;
            $scope.itemIds = $scope.charge.itemIds;
            $scope.surname = $scope.policy.surname; //投保人
            $scope.rnName = $scope.policy.rnName; //被保人
            $scope.beneClntNum = pageData.beneClntNum.trim();
            $scope.beneName = pageData.beneName; //权益人
            $scope.chargeType = "2";
            $scope.itemId = pageData.itemId;
            $scope.beneBankAcctKey = pageData.beneBankAcctKey;
            $scope.policyHolderClntNum = $scope.policy.cownnum01.trim();
            $scope.insurantClntNum = $scope.policy.lifcnum01;
            $scope.intimePayFlag = false;
            //页面定义的一些参数
            var Type = $scope.charge.type;
            var ReceiptAmount = $scope.charge.receiptAmount;
            var itemIds = $scope.charge.itemIds;
            var surname = $scope.policy.surname; //被保人
            var rnName = $scope.policy.rnName;
            var beneClntNum = pageData.beneClntNum.trim();
            var beneName = pageData.beneName; //权益人
            var chargeType = "2";
            var itemId = pageData.itemId;
            var beneBankAcctKey = pageData.beneBankAcctKey;
            var policyHolderClntNum = $scope.policy.cownnum01.trim();
            var insurantClntNum = $scope.policy.lifcnum01;

            var pendingFlag = pageData.pendingFlag;
            var isAfs = pageData.isAfs;

            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_条件判断 by  CYQ  20190912 start
            var offlineNeedSign = 'N';
            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_条件判断 by  CYQ  20190912 end

            //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 start
            var authorizedAmt = '999999999'; //授权总金额
            var paymentTimes = 0; //缴费次数
            var paymentDeadline = ''; //缴费截止日
            var limitPer; //每期扣款限额
            var currentAmount; //单笔授权金额的最低限制
            //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 end

            //S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 start
            //是否显示应退金额栏
            $scope.showchargeFee = false;
            $scope.showchangeFeetopic = false;
            $scope.showBeibaorenLabel = true; 
            $scope.itemList.forEach(item => {
                if (item.itemId != '15' && item.itemId != '30' && item.itemId != '29') {
                    $scope.showchargeFee = true;
                }else{
                	$scope.showchangeFeetopic = true;
                	$scope.showBeibaorenLabel = false; 
                } 
            })
            //S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 end
            /******************初始操作逻辑化操作逻辑begin**************/
            len = $scope.itemList.length;
            for (var i; i < len; i++) { //如果提交的修改里面包含itemId="55"，那么最后应退金额显示为“以保险合同约定为准”,否则正常显示统计金额
                if ($scope.itemList[i].itemId == "55") {
                    $scope.hbFlag = true;
                }
            }

            if ($scope.charge.type == "R") { //收费时才显示溢缴保费金额信息
                $scope.yjFlag = true;
                //追加改动，如果溢缴费用是0，则还是不显示
                if ($scope.pageData.fmtSpillPayFee == 0) {
                    $scope.yjFlag = false;
                }
            }

            //S2018122906735移动保全新增变更项目及功能的优化需求 add by yangyan 20200428 start
            //被保险人职业、保险计划、减额缴清、补充告知  结案类型仅受理，转人工 需要进入收付费页面
            var autoCheckFlag = true;
            for (var i = 0; i < $scope.itemList.length; i++) {
            	if ($scope.itemList[i].itemId == '15' || $scope.itemList[i].itemId == '29' || $scope.itemList[i].itemId == '30') {
                    autoCheckFlag = false;
                    break;
                }
            }
            if (pendingFlag != 'B' && isAfs == 'N' && autoCheckFlag) { //实时缴费显示情况
                //S2018122906735移动保全新增变更项目及功能的优化需求 add by yangyan 20200428 end
                $scope.intimePayFlag = true;
            }
            /*for(var i;i < pclist.length ; i ++){ //如果银行中fieldType为I，默认加个星号
            	if(pclist[i].fieldType=="I"){
            		pclist[i].bankdesc = pclist[i].bankdesc + "*";
            	}
            }*/
            //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）start
            //检查银行限额
            $scope.Bankaccount = {
                counts: 0
            }
            var isContain = false;
            for (var i = 0; i < $scope.itemList.length; i++) {
                //if ($scope.itemList[i].itemId == '04' || $scope.itemList[i].itemId == '17' || $scope.itemList[i].itemId == '23' || $scope.itemList[i].itemId == '33' || $scope.itemList[i].itemId == '37' || $scope.itemList[i].itemId == '38') {
                //S2018122906735移动保全新增变更项目及功能的优化需求 add by yangyan 20201022 start
                //04(缴别变更)、17(额外投资)、23(复效)、33(结束缓缴期)、37(补缴保障费用和保单管理费)、38(保单还款)、
                //11(被保险人职业)、15(保险计划)、29(取消承保条件)、30(补充告知)
                var currentItemId = $scope.itemList[i].itemId;
                if (currentItemId == '04' || currentItemId == '17' || currentItemId == '23' || currentItemId == '33' ||
                        currentItemId == '37' || currentItemId == '38' || currentItemId == '15' ||
                        currentItemId == '29' || currentItemId == '30') {
                    //S2018122906735移动保全新增变更项目及功能的优化需求 add by yangyan 20201022 end
                    //S2019112910966建设银行签约授权功能需求 add by yangyan 20200509 start
                    itemId = $scope.itemList[i].itemId;
                    //S2019112910966建设银行签约授权功能需求 add by yangyan 20200509 end
                    isContain = true;
                    break;
                }
            }

            if (isContain) {
                //加载缓存中存在的所有银行信息，重组银行列表显示
                myFactory.loadingShow();
                myFactory.banklimit(function successCallback(response) {
                    var errCode = response.data.errCode;
                    bankinfomations = response.data.banks;
                    console.log(bankinfomations);
                    if (errCode != '') {
                        myFactory.alert("", "当前系统繁忙，请稍后重试", "info");
                        myFactory.loadingHide();
                        return;
                    } else if (errCode == '' && bankinfomations.length == 0) {
                        myFactory.alert("", "当前系统繁忙，请稍后重试", "info");
                        myFactory.loadingHide();
                        return;
                    }

                    matchBankInfo();
                    myFactory.loadingHide();
                }, function error() {
                    myFactory.alert("", "当前系统繁忙，请稍后重试", "info");
                    myFactory.loadingHide();
                    return;
                });
            } else {
                for (var i = 0; i < pclist.length; i++) { //如果银行中fieldType为I，默认加个星号，在这之前，把原数据保存到pclistBack中
                    var a = {
                        bankdesc: pclist[i].bankdesc,
                        bankcode: pclist[i].bankcode
                    }
                    pclistBack.push(a);
                    if (pclist[i].fieldType == "I") {
                        //pclist[i].bankdesc = pclist[i].bankdesc + "*"; 要求不确定，先不加星号 ZZQ 2017-08-23
                    }
                }
            }
            if (isContain) {
                $scope.pclist = pclistBack; //处理完毕后绑定到页面
            } else {
                $scope.pclist = pclist; //处理完毕后绑定到页面
            }

            //			$scope.pclist = pclist; //处理完毕后绑定到页面
            //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）end

            if (user != null && user != "" && user != undefined) {
                userType = user.userType;
            }

            //如果实际缴费金额为0则不显示账号信息
            var _receipt = $scope.charge.receiptAmount; //	实际金额
            //S2018122906735移动保全新增变更项目及功能的优化需求 add by yangyan 20200428 start
            //被保险人职业、保险计划、减额缴清、补充告知  结案类型仅受理，转人工 需要进入收付费页面
            if (_receipt == 0 && !(strItemIds.indexOf("30") != '-1' || strItemIds.indexOf("15") != '-1' || strItemIds.indexOf("29") != '-1')) {
            //S2018122906735移动保全新增变更项目及功能的优化需求 add by yangyan 20200428 end
                //	  			divAccount.style.display = "none" ;
                $scope.divAccountFlag = false; //不显示
            }

            //开户城市初始化
            //客户新需求变更，不想初始带出默认值了，取消默认设置   BY ZZQ 2018-2-27
            /*if($("#newCity").val()==""){
	  			$("#newCity").val(citylist[0].citydesc.trim());
				$("#newCityCode").val(citylist[0].citycode.trim());
	  		}*/

            //如果变更项目中包含 39、40、47、43业务，则账户持有者显示权益人
            for (var i = 0; i < itemIds.length; i++) {
                var tmp = parseInt(itemIds[i]);
                if (tmp == 39 || tmp == 40 || tmp == 47 || tmp == 43) {
                    $("#policyholderMsg").hide(); //隐藏显示投保人
                    $("#beneNameMsg").show(); //显示权益人
                    beneFlag = true;
                    break;
                }
            }
            if (beneFlag) { //如果权益人标是true，那么授权其他账户中，户名就显示为是beneClntNum（已经在参数后台得到），否则默认是投保人的编号
                $("#paynum").val(beneClntNum);
            } else {
                $("#paynum").val(policyHolderClntNum);
            }


            /*********** 《S2019091010023 移动保全限制湖南分公司使用被保人账号进行保全缴费系统需求》 add by huanghaokun 20190923 start***********/
            //若首/续期账号为被保人账号，系统收费页面不显示“首/续期账号”
            if (hunan) {
                if (insurant) {
                    $("#account_renewal").hide();
                }
                if (insurantFir) {
                    $("#account_First").hide();
                }
            }
            /*********** 《S2019091010023 移动保全限制湖南分公司使用被保人账号进行保全缴费系统需求》 add by huanghaokun 20190923 end***********/

            //S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 start
            if(itemId.indexOf("15") != '-1' || itemId.indexOf("29") != '-1' || itemId.indexOf("30") != '-1'){
            	if (insurant) {
                    $("#account_renewal").hide();
                }
                if (insurantFir) {
                    $("#account_First").hide();
                }
            }
            //S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 end

            //控制是否大于50万[退费总金额大于50万时不能操作下一步按钮]
            //if( userType=="market" ){ //当用户的类型是market的时候，执行以下部分，_receipt是实际金额，已经在上面定义
            //S2018051403895_信易通人证合一及活体检测项目需求 取消原B/A/AA/AAA级营销员对应可受理退费金额20万/30万/40万/50万的限制规则 add by rqyang 20180728 begin
            /*if( userType=="AG" ){	
            	var userGrade = user.userGrade;
            	var isOverAmt = false;
            	
            	if( _receipt >= 500000 && userGrade=="3" ){//等级为3时，大于50W不能操作
            		isOverAmt = true;
            	}
            	if( _receipt >= 400000 && userGrade=="2" ){//等级为2时，大于40W不能操作
            		isOverAmt = true;
            	}
            	if( _receipt >= 300000 && userGrade=="1" ){//等级为1时，大于30W不能操作
            		isOverAmt = true;
            	}
            	if( _receipt >= 200000 && userGrade=="B" ){//等级为B时，大于20W不能操作
            		isOverAmt = true;
            	}
            	if( isOverAmt ){
            		//	显示提示内容
            		myFactory.alert("","本次变更的退费金额已超出授权额度，为保证客户资金安全，请客户亲临客服柜台办理。","info");
                	//	设置[下一步]按钮不可操作  
            		$("#next").addClass("disabled");
            	}
            }*/
            //S2018051403895_信易通人证合一及活体检测项目需求 取消原B/A/AA/AAA级营销员对应可受理退费金额20万/30万/40万/50万的限制规则 add by rqyang 20180728 end

            /******************初始操作逻辑化操作逻辑end**************/
            $scope.data = {};

            //重新受理
            $scope.renew = function() {
                    myFactory.renew();
                }
                //退出移动保全
            $scope.exit = function() {
                    myFactory.exit();
                }
                //返回上一步
            $scope.goBack = function() {
                    //history.go(-1);
                    //$("#hidenId").hide();
                    myFactory.goBack();
                }
                //客户须知弹窗
            $scope.tipOpen = function() {
                modal('open', 'tip_model', 'overwindowOnChargeRefund');
            }
            $scope.closeTip = function() {
                    modal('close', 'tip_model', 'overwindowOnChargeRefund');
                }
            //S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 start
            $scope.tipOpen2 = function() {
                modal('open', 'tip_model2', 'overwindowOnChargeRefund');
            }
            $scope.closeTip2 = function() {
                    modal('close', 'tip_model2', 'overwindowOnChargeRefund');
            }
            //S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 end

            //页面同意阅读协议复选框部分
            $scope.changeReadFlag = function() {
                    $scope.readFlag = !$scope.readFlag;
                }
                //城市选择弹窗	
            $scope.cityChose = function() {
                modal('open', 'city_model', 'overwindowOnChargeRefund');
            }
            $scope.cityClose = function() {
                    modal('close', 'city_model', 'overwindowOnChargeRefund');
                }
                //保单详情弹窗
            $scope.showPolicyDetail = function() {
                    modal('open', 'policyDetailModelOnChargeRefund', 'overwindowOnChargeRefund', 'policyDetailCloseXOnChargeRefund');
                }
                //保单详情弹窗关闭函数
            $scope.policyDetailCancel = function() {
                    modal('close', 'policyDetailModelOnChargeRefund', 'overwindowOnChargeRefund', 'policyDetailCloseXOnChargeRefund');
                }
                //关闭遮罩
            $scope.overwindowClose = function() {
                //$(".overwindow").show();
                $(".overwindow").hide();
                $(".overmodal").hide();
            }
            $scope.chargeTypeOclk = function(chargeType) {
                //function chargeTypeOclk(chargeType){
                if (chargeType == "2") {
                    $("#nintimeDiv").show();
                    $("#intimePayDiv").hide();
                } else {
                    $("#nintimeDiv").hide();
                    $("#intimePayDiv").show();
                }
                //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）add by csf 2019-04-19 start
                $('#showContractCase2').hide();
                //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）add by csf 2019-04-19 end
            }

            //指定退款授权方式
            $scope.changeGiveRight = function(type) {
                    if (type == "1") { //1-续期账户
                    	/*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 start*/
                    	$scope.giveRight2 = false;
                        $scope.giveRight3 = false;
    					if($scope.account!=null && $scope.account.bankcode == "67"){
                        	if($scope.giveRight1 == false){
        						$scope.giveRight1 = true;
        					}
                        	myFactory.alert("", "该银行不支持收退费，请选择其他银行", "info");
                        	$("#account").attr("checked",false);
                            return false;
                        }
    					if ($scope.giveRight1 == false) {
                            $scope.giveRight1 = true;
                            $("#accountFlag").val("1");
                        }
    					/*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 end*/

                        //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）start
                        if (isContain) {
                            checkbanklimit($scope.account.bankcode);
                            for (var i = 0; i < pclistBack.length; i++) {
                                if (pclistBack[i].bankcode == $scope.account.bankcode) {
                                    //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 start
                                    if (pclistBack[i].limit != '' && pclistBack[i].limit > 0 && pclistBack[i].limit != '999999999' && $scope.account.bankcode != '04') { //有限额
                                        //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 end
                                        $scope.Bankaccount.counts = pclistBack[i].limit;
                                        $('#showbankCause2').show();
                                        break;
                                    }
                                }
                            }
                        }
                        //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）end


                    } else if (type == "3") { //3-首期账户
                        /*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 start*/
    					$scope.giveRight1 = false;
    					$scope.giveRight2 = false;
    					if($scope.accountFir!=null && $scope.accountFir.bankcode3 == "67"){
    						if($scope.giveRight3 == false){
    							$scope.giveRight3 = true;
    						}
                        	myFactory.alert("", "该银行不支持收退费，请选择其他银行", "info");
                        	$("#accountFirst").attr("checked",false);
                            return false;
                        }
    					if($scope.giveRight3 == false){
    						$scope.giveRight3 = true;
    						$("#accountFlag").val("3");
    					}
    					/*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 end*/
    					
                        //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）start
                        if (isContain) {
                            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_条件判断 by  CYQ  20190912 start
                            checkbanklimit($scope.accountFir.bankcode3);
                            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_条件判断 by  CYQ  20190912 end
                            for (var i = 0; i < pclistBack.length; i++) {
                                if (pclistBack[i].bankcode == $scope.accountFir.bankcode3) {
                                    //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 start
                                    if (pclistBack[i].limit != '' && pclistBack[i].limit > 0 && pclistBack[i].limit != '999999999' && $scope.accountFir.bankcode3 != '04') { //有限额
                                        //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 end
                                        $scope.Bankaccount.counts = pclistBack[i].limit;
                                        $('#showbankCause1').show();
                                        break;
                                    }
                                }
                            }
                        }
                        //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）end


                    } else if (type == "2") { //2-其他账户
                        /*********** 《S2019091010023 移动保全限制湖南分公司使用被保人账号进行保全缴费系统需求》 add by huanghaokun 20190923 start***********/
                        //湖南保单，选择“授权其他账户”时，账户持有人默认显示投保人姓名，不显示被保险人
                        if (hunan) {
                            $('#beibaoren_label').hide();
                        } else {
                            $('#beibaoren_label').show();
                        }

                        /*********** 《S2019091010023 移动保全限制湖南分公司使用被保人账号进行保全缴费系统需求》 add by huanghaokun 20190923 end***********/
                        //S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20190315 start 
                        if (itemId == "15" || itemId == "29" || itemId == "30") {
                            $('#beibaoren_label').hide();
                        }
                        //S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20190315 end 

                        if ($scope.giveRight2 == false) {
                            $scope.giveRight2 = true;
                            $("#accountFlag").val("2");
                        }
                        $scope.giveRight1 = false;
                        $scope.giveRight3 = false;

                        if (beneFlag == true) { //如果是属于权益人那么户名paynme这只为权益人，并且让paynmeFlag这个隐藏为3
                            $("#paynme").val(beneName);
                            $("#paynmeFlag").val('3');
                        } else {
                            $("#paynme").val(surname);
                            $("#paynmeFlag").val('1');
                        }
                    }

                    //视图重新计算容器大小  S_Input_20180419 luxueyan add 20180419 处理输入框被输入法隐藏问题
                    //$ionicScrollDelegate.resize();
                }
                //返回上一页
            $scope.goback = function() {
                myFactory.goBack();
            }

            //关闭遮罩
            $scope.overwindowClose = function() {
                $(".overwindow").hide();
                $(".overmodal").hide();
            }

            //页面“账号持有人”单选按钮
            $scope.clntnmeOck = function(idVal) {
                    /*if(type=="1"){
                    	$scope.name = itemData.holderNm;//前端页面投保人姓名显示缓存投保人
                    	$("#changeName").html("投保人姓名");
                    }
                    if(type=="2"){
                    	$scope.name = itemData.insuredNm;//前端页面被保人姓名显示缓存被保人
                    	$("#changeName").html("被保人姓名");
                    }*/
                    var clntnme = $("input[name='clntnmeForChargeFee']:checked").val();
                    $("#paynme").val("");
                    if (clntnme == idVal && idVal == 1) {
                        $("#paynme").val($("#surname").val());
                        $("#paynum").val($("#policyHolderClntNum").val());
                        $("#paynmeFlag").val('1');
                    } else if (clntnme == idVal && idVal == 2) {
                        $("#paynme").val($("#rnName").val());
                        $("#paynum").val($("#insurantClntNum").val());
                        $("#paynmeFlag").val('2');
                    } else if (clntnme == idVal && idVal == 3) {
                        $("#paynme").val($("#beneName").val());
                        $("#paynmeFlag").val('3');
                    }
                }
                /*function clntnmeOck(idVal){
                	var clntnme = $("input[name='clntnme']:checked").val();
                	$("#paynme").val("");
                	if(clntnme == idVal && idVal == 1){
                		$("#paynme").val($("#surname").val());
                		$("#paynum").val($("#policyHolderClntNum").val());
                		$("#paynmeFlag").val('1');
                	}else if(clntnme == idVal && idVal == 2){
                		$("#paynme").val($("#rnName").val());
                		$("#paynum").val($("#insurantClntNum").val());
                		$("#paynmeFlag").val('2');
                	}else if(clntnme == idVal && idVal == 3){
                		$("#paynme").val($("#beneName").val());
                		$("#paynmeFlag").val('3');
                	}
                }*/

            //改变银行下拉框
            $scope.changeNewBank = function() {
                var options = "";
                options = $("#newBankSelect option:selected");
                console.log(options.text());
                console.log(options.val());
                $scope.newBank = options.text();
                //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）start
                //需要签约
                for (var i = 0; i < pclistBack.length; i++) {
                    if (pclistBack[i].bankcode == options.val()) {
                        if ((pclistBack[i].limit != '' && pclistBack[i].limit > 0) && pclistBack[i].limit != '999999999') { //有限额
                            $scope.Bankaccount.counts = pclistBack[i].limit;
                            sigleLimitAmount = pclistBack[i].sigleLimitAmount; //单日限额
                            dayLimitAmount = pclistBack[i].dayLimitAmount; //日累计限额
                            monthLimitAmount = pclistBack[i].monthLimitAmount; //月累计限额
                            dueDate = pclistBack[i].dueDate; //委托日期
                            //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 start
                            if (options.val() != '04') {
                                $('#showbankCause').show();
                            }
                            //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 end
                        } else {
                        	/*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 start*/
                        	if(pclistBack[i].limit != '' && pclistBack[i].limit > 0 && options.val() !='01' && options.val() !='71'){
                        		sigleLimitAmount = pclistBack[i].sigleLimitAmount; //单日限额
                                dayLimitAmount = pclistBack[i].dayLimitAmount; //日累计限额
                                monthLimitAmount = pclistBack[i].monthLimitAmount; //月累计限额
                                dueDate = pclistBack[i].dueDate; //委托日期
                        	}
                            /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 end*/
                            $('#showbankCause').hide();
                        }
                        break;
                    }
                }
                if (isContain) {
                    showDialog(options.text());

                }
                //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）end
            }

            //查找城市方法
            $scope.searchCity = function() {
                    var cityName = $("#searchCityParam").val();
                    var timestamp = myFactory.getTimetamp();
                    var sfis = "cityName-token-timestamp";
                    var signStr = "cityName=" + encodeURI(cityName) + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                    var sign = myFactory.hex(signStr);
                    $http({
                        method: 'GET',
                        url: app.domain + 'common/restSearchCity.action',
                        params: { 'cityName': cityName, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                    }).then(function successCallback(response) {
                        if (response.data.success) {
                            $scope.cityList = response.data.data; //绑定到页面
                        }
                    }, function errorCallback(response) {
                        $.alert({
                            title: '',
                            text: '初始化查询订单详情失败!',
                            onOK: function() {
                                //点击确认
                            }
                        });
                    });
                }
                //城市选择
            $scope.cityClick = function(cityCode, cityName) {
                $("#newCity").val(cityName.trim());
                $("#newCityCode").val(cityCode.trim());
            }

            /**
             * 只输入整数函数
             */
            $scope.keyNumPress = function() {
                var keyCode = event.keyCode;
                if (keyCode >= 48 && keyCode <= 57) {
                    event.returnValue = true;
                } else {
                    event.returnValue = false;
                }
            }

            /**
             * 银联在线缴费  ZZQ
             */
            $scope.intimePayMethod = function() {
                    //点击银联在线缴费，跳转实时缴费页面,通过后台来跳转，访问charge/restInit.action
                    myFactory.loadingShow(); //显示加载圈
                    var timestamp = myFactory.getTimetamp();
                    var sfis = "itemId-intime-token-timestamp";
                    var signStr = "itemId=" + itemId + "&intime=" + "1" + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                    var sign = myFactory.hex(signStr);
                    $http({
                        method: 'GET',
                        url: app.domain + 'charge/restInit.action',
                        params: { 'itemId': itemId, 'intime': "1", 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                    }).then(function successCallback(response) {
                        if (response.data.success) {
                            var intimeData = response.data.data.pageData; //得到数据
                            myFactory.loadingHide();
                            $ionicHistory.clearCache().then(function() {
                                $state.go('charge_intime', {
                                    itemId: itemId,
                                    chdrnum01: chdrnum01,
                                    chdrcoy: chdrcoy,
                                    intimeData: intimeData
                                });
                            })
                        } else {
                            myFactory.loadingHide();
                            myFactory.alert("", "数据提交后台时候出错，请返回重新尝试!", "info");
                        }
                    }, function errorCallback(response) {
                        myFactory.loadingHide();
                        myFactory.alert("", "数据提交后台时候出错，请返回重新尝试!", "info");
                    });
                }
                /**
                 * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                 * 新增签约接口的逻辑 add by csf 20180926 start
                 */
            var accountNo = ''; //账号
            var accountName; //户名
            var accountType = '00'; //银行卡类型，默认为银行卡
            var bankCode; //银行编号
            var bankNames; //银行名称
            var phoneNum; //手机号
            var code; //验证码
            var signMode; //签约类型
            var idType; //身份类型
            var id; //身份证号
            var vailddate; //信用卡有效期
            var cvv2; //信用卡cvv2
            var sigleLimitAmount = ""; //单日限额
            var dayLimitAmount = ""; //日累计限额
            var monthLimitAmount = ""; //月累计限额
            var dueDate = ""; //委托日期
            var agreePayCompanyCode = '';
            var bankinfomations;
            var cntbranch = $scope.policyData.chdrcoy + $scope.policyData.cntbranch; //当前保单号所属的机构

            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求) by  CYQ  20190910 start
            var idTypeName; //证件类型名称
            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求) by  CYQ  20190910 end

            $scope.idTypeLF = [
                { contractVal: '0', pasVal: '1', text: '身份证' },
                { contractVal: '1', pasVal: '7', text: '户口簿' },
                { contractVal: '2', pasVal: '2', text: '护照' },
                { contractVal: '3', pasVal: '3', text: '军官证' },
                { contractVal: '4', pasVal: '8', text: '士兵证' },
                { contractVal: '7', pasVal: '6', text: '出生证/临时身份证' },
                { contractVal: '5', pasVal: '4', text: '港澳居民来往内地通行证' },
                { contractVal: '6', pasVal: '9', text: '台湾同胞来往内地通行证' },
                //	                {value:'6',text:'出生证'},
                { contractVal: '8', pasVal: 'A', text: '外国人居留证' },
                { contractVal: '14', pasVal: 'B', text: '港澳居民居住证' },
                { contractVal: '15', pasVal: 'C', text: '台湾居民居住证' },
                { contractVal: 'x', pasVal: '5', text: '其他证件' }
            ];
            /**
             * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
             * 新增签约接口的逻辑 add by csf 20180926 end
             */
            $scope.nextStep = function() {
                    myFactory.loadingShow(); //显示加载圈
                    //总体控制标志，只有为true时候才能进行下一步
                    var isAllowNext = false;
                    //定义账号检测所需要的参数，在不同的方法里面填装
                    var params;

                    //如果实际缴费金额为0，那么标志为false，这时候不需要填写缴费授权，直接可以跳过校验执行下一步
                    if ($scope.divAccountFlag == false) {
                        isAllowNext = true; //实际缴费金额为0时直接返回真
                        toNextPage(isAllowNext);
                    } else {
                        var chargeType = $("input[name='chargeType']:checked").val(); //实时缴费:1,非实时缴费:2
                        var accountFlag = $("#accountFlag").val().trim();

                        if (chargeType == null || chargeType == undefined || chargeType == "") {
                            myFactory.alert("", "请选择缴费方式", "info");
                            myFactory.loadingHide();
                            return;
                        }

                        if (chargeType == 1) {
                            myFactory.alert("", "实时缴费请点击“银联在线缴费”进行缴费", "info");
                            myFactory.loadingHide();
                            return;
                        }

                        //如果没有同意协议，不给下一步
                        if ($scope.readFlag == false) {
                            myFactory.alert("", "请阅读并同意变更费用自动转账付款授权客户须知。", "info");
                            myFactory.loadingHide();
                            return;
                        }

                        //如果没有选择退费授权方式，则提示
                        if (chargeType == 2 && accountFlag == "") {
                            myFactory.alert("", "请选择续期账号、首期缴费账号或授权其他账号。", "info");
                            myFactory.loadingHide();
                            return false;
                        }

                        //accountFlag用于标志选用了哪种退费授权方式 ，续期为1，首期为3，授权其他账户为2
                        if (chargeType == 2 && accountFlag !== "" && (accountFlag == 1 || accountFlag == 3)) { //续期或者首期
                            var message = "";
                            var bankcodeVal = "";
                            var bankdescVal = "";
                            if (accountFlag == 1) {
                                message = "续期账号";
                                bankcodeVal = $('#bankcode1').val().trim();
                                bankdescVal = $('#bankdesc1').val().trim();
                                bankCode = $('#bankcode1').val().trim();
                                bankNames = $('#bankdesc1').val().trim()
                                accountName = $('#paynme1').val().trim();;
                            } else if (accountFlag == 3) {
                                message = "首期缴费账号";
                                bankcodeVal = $('#bankcode3').val().trim();
                                bankdescVal = $('#bankdesc3').val().trim();
                                bankCode = $('#bankcode3').val().trim();
                                bankNames = $('#bankdesc3').val().trim();
                                accountName = $('#paynme3').val().trim();
                            }
                            if (bankcodeVal == "") {
                                //$("#xuzhi").testRemind(message+"为空。");
                                myFactory.alert("", message + "为空。", "info");
                                myFactory.loadingHide();
                                return false;
                            }
                            
                            //S2022032221693-农业银行客户签约补充需求 add by huanghaokun 20220526 start
                            //统一下签约银行名称
                            if (accountFlag == 1 || accountFlag == 3) {
                            	for (var i = 0; i < pclist.length; i++) {
                                    if (bankCode == pclist[i].bankcode) {
                                    	bankNames = pclist[i].bankdesc;
                                        break;
                                    }
                                }
                            }
                            //S2022032221693-农业银行客户签约补充需求 add by huanghaokun 20220526 end

                            // Added by ChrisChen S2016091903954 删除信用卡缴费银行账户设置需求 20161025 begin
                            //var bankdescVal = $('#bankdesc1').val().trim();
                            if (bankdescVal == "中信信用卡" || bankdescVal == "中信联名信用卡" || bankdescVal == "工行信用卡") {
                                myFactory.alert("", "信用卡账户不可用于变更缴费，请选择其它银行账户。", "info");
                                myFactory.loadingHide();
                                return false;
                            }
                            if (bankdescVal == "渣打银行") {
                                myFactory.alert("", "该银行暂未开通单次缴费业务，请选择其他银行账户", "info");
                                myFactory.loadingHide();
                                return false;
                            }
                            // Added by ChrisChen S2016091903954 删除信用卡缴费银行账户设置需求 20161025 end

                            if (bankcodeVal == "18" || bankcodeVal == "19" || bankcodeVal == "25" || bankcodeVal == "37" || bankcodeVal == "50" || bankcodeVal == "31") {
                                //$("#xuzhi").testRemind(message+"银行不能办理，谢谢！");
                                myFactory.alert("", message + "银行不能办理，谢谢！", "info");
                                myFactory.loadingHide();
                                return false;
                            }
                            
                            /*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 start*/
                            if(bankcodeVal == "67"){
                            	myFactory.alert("", "该银行不支持收退费，请选择其他银行", "info");
                                myFactory.loadingHide();
                                return false;
                            }
                            /*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 end*/

                            if (accountFlag == 3) { //首期缴费账号
                                var ret = true;
                                var paynum3 = $('#paynum3').val().trim(); //	首期客户号
                                var _bankacctkey3 = $('#bankacctkey3').val().trim(); //	银行账号
                                var _city = $('#city3').val(); //	银行开户城市代码
                                var _paynmeFlag = "3"; //	客户类型[1-投保人,2-被保人,3-受益人]
                                var _flag = "Y"; //	是否建账号[Y-是,N-否]


                                var timestamp = myFactory.getTimetamp();
                                var sfis = "token-timestamp";
                                var signStr = "token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                                var sign = myFactory.hex(signStr);
                                params = { 'bankcode': bankcodeVal, 'bankacctkey': _bankacctkey3, 'city': _city, 'paynmeFlag': _paynmeFlag, 'flag': _flag, 'beneClntNum': paynum3, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp };
                                //params = {'bankcode':bankcode3,'bankacctkey':bankacctkey3,'city':_city,'paynmeFlag':_paynmeFlag,'flag':_flag,'beneClntNum':paynum3,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp };
                                accountNo = _bankacctkey3;
                                /*var param = {'bankcode':bankcodeVal,'bankacctkey':_bankacctkey3,'city':_city,'paynmeFlag':_paynmeFlag,'flag':_flag,'beneClntNum':paynum3 };
                                jQuery.ajax({
                                	type:"post",
                                	url:basePath+"/charge/check.action",
                                	data:param,
                                	async:false,
                                	dataType:"JSON",
                                	success:function(data){
                                		if(data == "fail"){
                                			$("#bankacctkeyCon").testRemind("客户录入账号已被其它客户占用，请返回重新确认账号是否有误，如确认无误，请联系您的服务营销员或亲自来我司办理相关变更申请，办理时需提供你的存折卡复印件或开户证明文件，谢谢！");
                                			ret =  false;
                                		}
                                	}
                                });
                                return ret;*/
                            }
                            if (accountFlag == 1) {
                                accountNo = $('#bankacctkey1').val().trim(); //	银行账号
                            }
                            idType = $scope.policyData.roleflag35; //证件类型
                            id = $scope.policyData.secuityno; //证件号
                            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求) by  yangyan  20191010 start
                            //如果账号持有人为被保险人且投被保险人不一致，则获取被保险人证件类型，证件号
                            if (accountName == $scope.policyData.rnName && $scope.policyData.surname != $scope.policyData.rnName) {
                                idType = $scope.policyData.rnrolefag35; //证件类型
                                id = $scope.policyData.rnIdNumber; //证件号码
                            }
                            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求) by  yangyan  20191010 end
                        }

                        /**
                         * 授权其他银行账户
                         */
                        if (chargeType == 2 && accountFlag != "" && accountFlag == 2) {
                            var options = "";
                            options = $("#newBankSelect option:selected");
                            var bankcode = options.val();

                            var banKName = $("#newBank").val(); //银行名称
                            var cityCode = $("#newCityCode").val(); //城市代码
                            var bankacctkey = $("#bankacctkey").val(); //	银行账号
                            bankacctkey = bankacctkey.replace(/\s+/g, "");
                            if (bankacctkey == "") {
                                myFactory.alert("", "请输入银行账号", "info");
                                myFactory.loadingHide();
                                return;
                            } else {
                                //						var Reg =/^[0-9]/;
                                //			        	if (!Reg.test(bankacctkey)) {
                                //			        		$("#bankacctkey").testRemind("请输入正确账号。");
                                //			    			return false;
                                //			        	}
                                var item;
                                var flag = false;
                                for (var i = 0; i < bankacctkey.length; i++) {
                                    item = bankacctkey.charAt(i);
                                    if (isNaN(item)) { //item为非数字
                                        flag = true;
                                    }
                                }
                                if (flag == true) {
                                    myFactory.alert("", "银行账号/卡号请输入数字！", "info");
                                    myFactory.loadingHide();
                                    return;
                                }
                            }
                            /**
                             * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                             * 新增签约接口的逻辑 add by csf 20180926 start
                             */
                            bankCode = bankcode;
                            bankNames = $("#newBank").val();
                            accountNo = bankacctkey;
                            accountName = $('#paynme').val().trim();
                            /**
                             * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                             * 新增签约接口的逻辑 add by csf 20180926 end
                             */
                            //						var bankacctkeyCon = $("#bankacctkeyCon").val();
                            //						if(bankacctkeyCon == ""){
                            //							myFactory.alert("","请输入确认账号。","info");
                            //							return;
                            //						}else{
                            //							//						var Reg =/^[0-9]/;
                            //							//			        	if (!Reg.test(bankacctkeyCon)) {
                            //							//			        		$("#bankacctkeyCon").testRemind("请输入正确账号。");
                            //							//			    			return false;
                            //							//			        	}
                            //							var item;
                            //							var flag=false;
                            //							for(var i=0;i<bankacctkeyCon.length;i++){
                            //								item=bankacctkeyCon.charAt(i);
                            //								if(isNaN(item)){//item为非数字
                            //									flag=true;
                            //								}
                            //							}
                            //							if(flag==true){
                            //								myFactory.alert("","确认银行账号/卡号请输入数字！","info");
                            //								return;
                            //							}
                            //						}
                            //						if(bankacctkey != bankacctkeyCon){
                            //							myFactory.alert("","银行账号/卡号账号不一致。","info");
                            //							return;
                            //						}

                            if (banKName == undefined || banKName == null || banKName == "") {
                                myFactory.alert("", "请选择开户银行", "info");
                                myFactory.loadingHide();
                                return;
                            }

                            if (cityCode == undefined || cityCode == null || cityCode == "") {
                                myFactory.alert("", "请选择开户城市", "info");
                                myFactory.loadingHide();
                                return;
                            }


                            var ret = false;
                            //					var acctCheckFlag = false; 	//	是否有账号检测操作[false-没有,true-有]
                            var _beneClntNum = beneClntNum; //	受益人客户号（生存金受益人的客户号）
                            var _bankcode = bankcode; //	银行代码
                            var _city = $("#newCityCode").val(); //	银行开户城市代码
                            var _paynmeFlag = $("#paynmeFlag").val(); //	客户类型[1-投保人,2-被保人,3-受益人]
                            var _flag = "Y"; //	是否建账号[Y-是,N-否]
                            var timestamp = myFactory.getTimetamp();
                            var sfis = "bankcode-bankacctkey-paynmeFlag-flag-beneClntNum-token-timestamp";
                            var signStr = 'bankcode=' + _bankcode + '&bankacctkey=' + bankacctkey + '&paynmeFlag=' + _paynmeFlag + '&flag=' + _flag + '&beneClntNum=' + _beneClntNum + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                            var sign = myFactory.hex(signStr);
                            params = { 'bankcode': _bankcode, 'bankacctkey': bankacctkey, 'city': _city, 'paynmeFlag': _paynmeFlag, 'flag': _flag, 'beneClntNum': _beneClntNum, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp };
                            //			        在这里就提交的话会存在异步问题，统一提取到下面再做操作
                            //			        $http({
                            //						method: 'GET',
                            //						url: app.domain + '/charge/restCheck.action',
                            //						params: {'bankcode':_bankcode,'bankacctkey':bankacctkey,'city':_city,'paynmeFlag':_paynmeFlag,'flag':_flag,'beneClntNum':_beneClntNum }
                            //					}).then(function successCallback(response) {
                            //						if (response.data.success) {
                            //							var message = response.data.data.message;
                            //							if(message == "fail"){
                            //								myFactory.alert("","客户录入账号已被其它客户占用，请返回重新确认账号是否有误，如确认无误，请联系您的服务营销员或亲自来我司办理相关变更申请，办理时需提供你的存折卡复印件或开户证明文件，谢谢！","info");
                            //								return;
                            //							}
                            //						}
                            //					}, function errorCallback(response) {
                            //						网路不顺畅时提示(没有进入后台的"账号检测"逻辑)
                            //						myFactory.alert("","请确认当前网路是否顺畅或重新提交数据！","info");
                            //					});
                            /**
                             * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                             * 新增签约接口的逻辑 add by csf 20180926 start
                             */
                            if ($("input[name='clntnmeForChargeFee']:checked").val() == '1') {
                                idType = $scope.policyData.roleflag35; //证件类型
                                id = $scope.policyData.secuityno; //证件号
                            } else {
                                idType = $scope.policyData.rnrolefag35; //证件类型
                                id = $scope.policyData.rnIdNumber; //证件号码
                            }
                            /**
                             * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                             * 新增签约接口的逻辑 add by csf 20180926 end
                             */
                        }
                        /**
                         * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                         * 新增签约接口的逻辑 add by csf 20180926 start
                         */
                        phoneNum = $scope.policyData.mobilphone;
                        code = ''; //验证码
                        signMode = '02'; //请求类型
                        for (var i = 0; i < $scope.idTypeLF.length; i++) {
                            if ($scope.idTypeLF[i].pasVal === idType) {
                                idType = $scope.idTypeLF[i].contractVal; //证件类型
                                //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求) by  CYQ  20190910 start
                                idTypeName = $scope.idTypeLF[i].text; //证件类型名称
                                //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求) by  CYQ  20190910 end
                                break;
                            }
                        }
                        idType = idType.trim();
                        vailddate = ''; //信用卡的有效期
                        cvv2 = ''; //信用卡的CVV2编号
                        if (accountNo == '') {
                            myFactory.alert('提示', '账号信息未录入，请输入相关信息！');
                            myFactory.loadingHide();
                            return;
                        }
                        /**
                         * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                         * 新增签约接口的逻辑 add by csf 20180926 end
                         */
                        /*S2023011824901-官微授权银行页面超限额无拦截、非签约银行进入签约页面问题 add by huanghk 20230216 start*/
                        if(Number($scope.Bankaccount.counts)>0 && Number($scope.Bankaccount.counts)<Number(pageData.fmtFactFeeTotal)){
                        	 myFactory.alert("","缴费金额超出银行转账限额，请您选择其它银行账户","info");
                        	 myFactory.loadingHide();
                             return;
                        }
                        /*S2023011824901-官微授权银行页面超限额无拦截、非签约银行进入签约页面问题 add by huanghk 20230216 end*/
                        
                        //处理完分支校验，对于金额不为零时，来到这里进入一个提交后台总校验，方式1不需要提交后台校验，直接跳下个页面
                        if (accountFlag != "" && accountFlag == "1") {
                            isAllowNext = true;
                            /**
                             * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                             * 新增签约接口的逻辑 add by csf 20180926 start
                             */
                            //判断全局变量，是否已经签约完成了，是的话，不检查下面的，直接进行接下来的 add by csf 20180926
                            if ($rootScope['isCon' + accountNo + itemId]) {
                                toNextPage(isAllowNext);
                                return;
                            }


                            if (isContain) {
                                myFactory.goBankContract(bankSuccess, bankError);
                            } else {
                                toNextPage(isAllowNext);
                            }
                            /**
                             * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                             * 新增签约接口的逻辑 add by csf 20180926 end
                             */
                        } else if ((accountFlag != "" && accountFlag == "3") || (accountFlag != "" && accountFlag == "2")) {
                            $http({
                                method: 'GET',
                                url: app.domain + '/charge/restCheck.action',
                                params: params
                            }).then(function successCallback(response) {
                                if (response.data.success) {
                                    var message = response.data.data.message;
                                    if (message == "fail") {
                                        //myFactory.alert("","客户录入账号已被其它客户占用，请返回重新确认账号是否有误，如确认无误，请联系您的服务营销员或亲自来我司办理相关变更申请，办理时需提供你的存折卡复印件或开户证明文件，谢谢！","info");
                                        myFactory.alert("", "客户录入账号已被其他客户占用，请重新确认账号是否有误，如确认无误，请通过书面形式办理本次申请，办理时需提供您的存折卡复印件或开户证明文件。", "info");
                                        myFactory.loadingHide();
                                        return;
                                    } else {
                                        isAllowNext = true;
                                        /**
                                         * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                                         * 新增签约接口的逻辑 add by csf 20180926 start
                                         */
                                        //判断全局变量，是否已经签约完成了，是的话，不检查下面的，直接进行接下来的 add by csf 20180926
                                        if ($rootScope['isCon' + accountNo + itemId]) {
                                            toNextPage(isAllowNext);
                                            return;
                                        }
                                        //开始判断是否需要进行签约操作
                                        if (isContain) {
                                            myFactory.goBankContract(bankSuccess, bankError);

                                        } else {
                                            toNextPage(isAllowNext);
                                        }
                                        /**
                                         * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
                                         * 新增签约接口的逻辑 add by csf 20180926 end
                                         */
                                    }
                                }
                            }, function errorCallback(response) {
                                //网路不顺畅时提示(没有进入后台的"账号检测"逻辑)
                                myFactory.loadingHide();
                                myFactory.alert("", "请确认当前网路是否顺畅或重新提交数据！", "info");
                            });
                        }

                    } //这层括号是分类金额是否为0时候的分支
                } //这层括号是nextStep()的结尾

            //封装数据提交后台，准备跳转下一个页面的函数
            function toNextPage(isAllowNext) {
                //isAllowNext==false时什么都不操作
                if (isAllowNext == true) {
                    //符合条件，跳转到查阅界面 
                    //封装、处理数据
                    var bankacctkey = $("#bankacctkey").val();
                    bankacctkey = bankacctkey.replace(/\s+/g, "");
                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start

                    /*移动保全问题反馈-保单选择退费账户为续期，却上传了其它银行卡影像件 add by huanghk 20221010 start*/
                    var accountFlag = $("#accountFlag").val().trim();
                    var bankCardItems = {
                        bankAccNum: bankacctkey,
                        accountFlag:accountFlag
                    }
                    if (accountFlag=="2" && $scope.bankCardNum == bankacctkey) {
                        bankCardItems['bigPic'] = $scope.bigPic;
                    }
                    /*移动保全问题反馈-保单选择退费账户为续期，却上传了其它银行卡影像件 add by huanghk 20221010 end*/
                    var timestamp = myFactory.getTimetamp();
                    var sfis = "token-timestamp";
                    var signStr = "token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                    var sign = myFactory.hex(signStr);
                    $http({
                        method: 'POST',
                        url: app.domain + 'img/saveBankCardCache.action',
                        data: { paramsMap: bankCardItems, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                    }).then(function successCallback(response) {
                        if (response.data.success) {
                            console.log("saveBankCardCache ok");
                        }
                    }, function errorCallback(response) {
                        console.log("saveIdCardCache error");
                    });

                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                    //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能） 银行限额以及银行签约信息展示 add by csf  start
                    var bankName = $("#newBankSelect option:selected").text().trim();
                    if (bankName.indexOf('(') > 0) {
                        bankName = bankName.substring(0, bankName.indexOf("("));
                    }
                    //S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）银行限额以及银行签约信息展示 add by csf end
                    var pageData2 = {
                        "accountFlag": $("#accountFlag").val().trim(),
                        "bankacctkey": bankacctkey,
                        "bankacctkey1": $("#bankacctkey1").val().trim(),
                        "bankacctkey3": $("#bankacctkey3").val().trim(),
                        "bankacctkeyCon": $("#bankacctkey").val().trim(), //不再采用需要输入第二次重复银行账户，用一个值就行了 BY ZZQ 2017/8/21
                        "bankcode": $("#newBankSelect option:selected").val().trim(),
                        "bankcode1": $("#bankcode1").val().trim(),
                        "bankcode3": $("#bankcode3").val().trim(),
                        "bankdesc": bankName,
                        "bankdesc1": $("#bankdesc1").val().trim(),
                        "bankdesc3": $("#bankdesc3").val().trim(),
                        "beneClntNum": beneClntNum,
                        "chargeType": chargeType,
                        "city": $("#newCityCode").val().trim(),
                        "city1": $("#city1").val().trim(),
                        "city3": $("#city3").val().trim(),
                        "citydesc": $("#newCity").val().trim(),
                        "citydesc1": $("#citydesc1").val().trim(),
                        "citydesc3": $("#citydesc3").val().trim(),
                        "itemIds": itemIds,
                        "paynme": $("#paynme").val().trim(),
                        "paynme1": $("#paynme1").val().trim(),
                        "paynme3": $("#paynme3").val().trim(),
                        "paynmeFlag": $("#paynmeFlag").val().trim(),
                        "paynum": $("#paynum").val().trim(),
                        "paynum1": $("#paynum1").val().trim(),
                        "paynum3": $("#paynum3").val().trim(),
                        "receiptAmount": ReceiptAmount,
                        "type": Type
                    }

                    $scope.pageData = $stateParams.pageData;
                    myFactory.loadingHide();
                    $ionicHistory.clearCache().then(function() {
                        $state.go('charge_refund_preview', {
                            itemId: itemId,
                            chdrnum01: chdrnum01,
                            chdrcoy: chdrcoy,
                            pageData: $scope.pageData,
                            pageData2: pageData2,
                            itemCommonList: itemCommonList,
                            //S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 start
                            strItemIds: strItemIds,
                            isSamePerson: isSamePerson
                			//S2018122906735移动保全新增变更项目及功能的优化需求 add by mqz 20200901 end
                        });
                    })
                }
            }

            /**
             * 扫描银行卡信息
             */
            $scope.scanBankCardInfoChargeFee = function() {
                    //移动端
                    cordova.sino.getBankCardInfo(function(result) {
                        if (result.success) {
                            if (!result.data.exit) {
                                if (appVersion === "IOS") {
                                    if (result.data.ok) {
                                        /*********************************待开发逻辑代码区域begin**********************************/
                                        var cardNumber = result.data.CardNumber; //卡号
                                        var cardInsName = result.data.CardInsName; //领取银行
                                        var bankCardType = result.data.BankCardType; //银行卡类型
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                        if (bankCardType.indexOf('贷') >= 0) {
                                            myFactory.alert("", "信用卡账户不允许授权，请选择储蓄卡", "info");
                                            return;
                                        }
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                        //alert(CardNumber+","+CardInsName+","+BankCardType);
                                        cardNumber = cardNumber.replace(/ /g, "");
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                        $scope.bankCardNum = cardNumber;
                                        $scope.bigPic = result.data.bigPic;
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                        $("#bankacctkey").val(cardNumber);
                                        //自动填充开户银行
                                        var flag = false;
                                        for (var i = 0; i < pclistBack.length; i++) {
                                            if (pclistBack[i].bankdesc.indexOf(cardInsName) >= 0) {
                                                $scope.newBankSelect = pclistBack[i].bankcode;
                                                $("#newBankSelect").val(pclistBack[i].bankcode);
                                                //$scope.newBank = pclistBack[i].bankdesc;
                                                $("#newBank").val(pclistBack[i].bankdesc);
                                                /**
                                                 * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能） add by csf 20180926 start
                                                 */
                                                showDialog2(pclistBack[i].bankcode);
                                                if (isContain) {
                                                    showDialog(pclistBack[i].bankdesc);
                                                }
                                                sigleLimitAmount = pclistBack[i].sigleLimitAmount; //单日限额
                                                dayLimitAmount = pclistBack[i].dayLimitAmount; //日累计限额
                                                monthLimitAmount = pclistBack[i].monthLimitAmount; //月累计限额
                                                dueDate = pclistBack[i].dueDate; //委托日期
                                                /**
                                                 * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能） add by csf 20180926 end
                                                 */
                                                flag = true;
                                            }
                                        }
                                        if (!flag) {
                                            //没有扫描识别到银行名称，则通过配置名称进行匹配
                                            var bankName = myFactory.bankNameMatching(cardInsName);
                                            //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                            if ('' != bankName) {
                                                //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                                for (var i = 0; i < pclistBack.length; i++) {
                                                    if (pclistBack[i].bankdesc.indexOf(bankName) >= 0) {
                                                        $scope.newBankSelect = pclistBack[i].bankcode;
                                                        $("#newBankSelect").val(pclistBack[i].bankcode);
                                                        $("#newBank").val(pclistBack[i].bankdesc);
                                                        /**
                                                         * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能） add by csf 20180926 start
                                                         */
                                                        showDialog2(pclistBack[i].bankcode);
                                                        if (isContain) {
                                                            showDialog(pclistBack[i].bankdesc);
                                                        }
                                                        sigleLimitAmount = pclistBack[i].sigleLimitAmount; //单日限额
                                                        dayLimitAmount = pclistBack[i].dayLimitAmount; //日累计限额
                                                        monthLimitAmount = pclistBack[i].monthLimitAmount; //月累计限额
                                                        dueDate = pclistBack[i].dueDate; //委托日期
                                                        /**
                                                         * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能） add by csf 20180926 end
                                                         */
                                                        flag = true;
                                                    }
                                                }
                                                //S2019111110714银行卡识别错误 add by yangyan 20191126 start	
                                            }
                                            //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                            if (!flag) {
                                                //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                                //myFactory.alert("","部分数据已自动填入，但查找不到开户银行，请手动选择开户银行与开户城市","info");
                                                myFactory.alert("", "部分数据已自动填入，但开户银行不在可选银行列表范围", "info");
                                                //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                            } else {
                                                myFactory.alert("", "部分数据已自动填入，请手动选择开户城市", "info");
                                            }
                                        } else {
                                            myFactory.alert("", "部分数据已自动填入，请手动选择开户城市", "info");
                                        }
                                        /*********************************待开发逻辑代码区域end**********************************/
                                    }
                                } else {
                                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                    $scope.bigPic = result.data.bigPic;
                                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                    cordova.sino.confirmBankCardInfo(function(result) {
                                        if (result.success) {
                                            if (result.data.ok) {
                                                /*********************************待开发逻辑代码区域begin**********************************/
                                                var cardNumber = result.data.CardNumber; //卡号
                                                var cardInsName = result.data.CardInsName; //领取银行
                                                var bankCardType = result.data.BankCardType; //银行卡类型
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                                if (bankCardType.indexOf('贷') >= 0) {
                                                    myFactory.alert("", "信用卡账户不允许授权，请选择储蓄卡", "info");
                                                    return;
                                                }
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                                //alert(CardNumber+","+CardInsName+","+BankCardType);
                                                cardNumber = cardNumber.replace(/ /g, "");
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                                $scope.bankCardNum = cardNumber;

                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                                $("#bankacctkey").val(cardNumber);
                                                //自动填充开户银行
                                                var flag = false;
                                                for (var i = 0; i < pclistBack.length; i++) {
                                                    if (pclistBack[i].bankdesc.indexOf(cardInsName) >= 0) {
                                                        $scope.newBankSelect = pclistBack[i].bankcode;
                                                        $("#newBankSelect").val(pclistBack[i].bankcode);
                                                        //$scope.newBank = pclistBack[i].bankdesc;
                                                        $("#newBank").val(pclistBack[i].bankdesc);
                                                        /**
                                                         * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能） add by csf 20180926 start
                                                         */
                                                        showDialog2(pclistBack[i].bankcode);
                                                        if (isContain) {
                                                            showDialog(pclistBack[i].bankdesc);
                                                        }
                                                        sigleLimitAmount = pclistBack[i].sigleLimitAmount; //单日限额
                                                        dayLimitAmount = pclistBack[i].dayLimitAmount; //日累计限额
                                                        monthLimitAmount = pclistBack[i].monthLimitAmount; //月累计限额
                                                        dueDate = pclistBack[i].dueDate; //委托日期
                                                        /**
                                                         * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能） add by csf 20180926 end
                                                         */
                                                        flag = true;
                                                    }
                                                }
                                                if (!flag) {
                                                    //没有扫描识别到银行名称，则通过配置名称进行匹配
                                                    var bankName = myFactory.bankNameMatching(cardInsName);
                                                    //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                                    if ('' != bankName) {
                                                        //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                                        for (var i = 0; i < pclistBack.length; i++) {
                                                            if (pclistBack[i].bankdesc.indexOf(bankName) >= 0) {
                                                                $scope.newBankSelect = pclistBack[i].bankcode;
                                                                $("#newBankSelect").val(pclistBack[i].bankcode);
                                                                $("#newBank").val(pclistBack[i].bankdesc);
                                                                /**
                                                                 * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能） add by csf 20180926 start
                                                                 */
                                                                showDialog2(pclistBack[i].bankcode);
                                                                if (isContain) {
                                                                    showDialog(pclistBack[i].bankdesc);
                                                                }
                                                                sigleLimitAmount = pclistBack[i].sigleLimitAmount; //单日限额
                                                                dayLimitAmount = pclistBack[i].dayLimitAmount; //日累计限额
                                                                monthLimitAmount = pclistBack[i].monthLimitAmount; //月累计限额
                                                                dueDate = pclistBack[i].dueDate; //委托日期
                                                                /**
                                                                 * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能） add by csf 20180926 end
                                                                 */
                                                                flag = true;
                                                            }
                                                        }
                                                        //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                                    }
                                                    //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                                    if (!flag) {
                                                        //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                                        //myFactory.alert("","部分数据已自动填入，但查找不到开户银行，请手动选择开户银行与开户城市","info");
                                                        myFactory.alert("", "部分数据已自动填入，但开户银行不在可选银行列表范围", "info");
                                                        //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                                    } else {
                                                        myFactory.alert("", "部分数据已自动填入，请手动选择开户城市", "info");
                                                    }
                                                } else {
                                                    myFactory.alert("", "部分数据已自动填入，请手动选择开户城市", "info");
                                                }
                                                /*********************************待开发逻辑代码区域end**********************************/
                                            }
                                        } else {
                                            myFactory.alert('', '扫描银行卡信息失败:' + result.data.errormsg, 'info');
                                        }
                                    }, result.data)
                                }
                            }
                        } else {
                            //sino.alert("扫描银行卡信息失败:"+result.data.errormsg);
                            myFactory.alert('', '扫描银行卡信息失败:' + result.data.errormsg, 'info');
                        }
                    });

                    //				//PC端开发测试用
                    //				var result = {
                    //					data : {
                    //						CardNumber:"62166 78911 1145 23785",
                    //						CardInsName:"中国银行",
                    //						BankCardType:"借记卡",
                    //						ok:true
                    //					}
                    //				};
                    //				if(result.data.ok){
                    //
                    //					/*********************************待开发逻辑代码区域begin**********************************/
                    //					var cardNumber=result.data.CardNumber;//卡号
                    //					var cardInsName=result.data.CardInsName;//领取银行
                    //					var bankCardType=result.data.BankCardType;//银行卡类型
                    //					//alert(CardNumber+","+CardInsName+","+BankCardType);
                    //				    cardNumber = cardNumber.replace(/ /g,"");
                    //				    $("#bankacctkey").val(cardNumber);
                    //					//自动填充开户银行
                    //					var flag = false;
                    //					for(var i=0 ; i<pclistBack.length ; i++){
                    //						if(pclistBack[i].bankdesc.indexOf(cardInsName)>=0){
                    //							$scope.newBankSelect = pclistBack[i].bankcode;
                    //							$("#newBankSelect").val(pclistBack[i].bankcode);
                    //							//$scope.newBank = pclistBack[i].bankdesc;
                    //							$("#newBank").val(pclistBack[i].bankdesc);
                    //							flag = true;
                    //						}
                    //					}
                    //					
                    //					if(!flag){
                    //						myFactory.alert("","部分数据已自动填入，但查找不到领取银行，请手动选择领取银行与开户城市","info");
                    //					}else{
                    //						myFactory.alert("","部分数据已自动填入，请手动选择开户城市","info");
                    //					}
                    //					/*********************************待开发逻辑代码区域end**********************************/
                    //				}

                } //扫描银行卡信息函数END

            /*add S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）--增加功能开关  by jiyongchang 20181211 start */
            function bankSuccess(response) {
                var resCode = response.data.returnCode;
                //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_条件判断 by  CYQ  20190912 start
                for (var j = 0; j < bankinfomations.length; j++) {
                    if (bankCode == bankinfomations[j].reqBankCode) {
                        if (bankinfomations[j].offlineNeedSign == 'Y') {
                            offlineNeedSign = 'Y';
                            break;
                        }
                    }
                }
                //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 start
                /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 start*/
                //if (resCode == '0' && (bankCode == '01' || bankCode == '71' || bankCode == '04')) {
                if (resCode == '0') {
                /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 end*/
                    //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 end
                    //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_条件判断 by  CYQ  20190912 end
                    contract();
                } else {
                    toNextPage(true);
                }
            }

            function bankError(response) {
                myFactory.alert("", "获取签约开关异常，请稍后重试", "info");
                myFactory.loadingHide();
                return;
            }
            /*add S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）--增加功能开关  by jiyongchang 20181211 end */

            /**
             * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
             * 新增签约接口的逻辑 add by csf 20180926 start
             */
            //显示签约银行提示语
            function showDialog(name) {
                if (name.indexOf("签约") >= 0) {
                    $('#showContractCase2').show();
                } else {
                    $('#showContractCase2').hide();
                }
            }
            //显示银行限额提示语
            function showDialog2(bankCode) {
                $scope.$apply(function() {
                    for (var i = 0; i < pclistBack.length; i++) {
                        if (pclistBack[i].bankcode == bankCode) {
                            //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 start
                            if ((pclistBack[i].limit != '' && pclistBack[i].limit > 0) && pclistBack[i].limit != '999999999' && bankCode != '04') { //有限额
                                //S2019112910966建设银行签约授权功能需求 add by yangyan 20200220 end
                                $scope.Bankaccount.counts = pclistBack[i].limit;
                                $('#showbankCause').show();
                            } else {
                                $('#showbankCause').hide();
                            }
                            break;
                        }
                    }
                });
            }

            function contract() {
                console.log("该保单的所属机构是：" + cntbranch);
                //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 start
                //S2023103027791个人养老年金项目保全系统优化需求 update by huanghk 20231127 start
                myFactory.goContract(accountNo, accountName, accountType, bankCode, phoneNum, code, signMode, '1', cntbranch, pageData.fmtFactFeeTotal, idType, id,
                    vailddate, cvv2, sigleLimitAmount, dayLimitAmount, monthLimitAmount, dueDate, successCall, errorCall,
                    /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 start*/
                    //chdrnum01, itemId, paymentTimes, paymentDeadline, '0');
                    chdrnum01, itemId, paymentTimes, paymentDeadline, '0','','','','','','');
                   /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 end*/
                 //S2023103027791个人养老年金项目保全系统优化需求 update by huanghk 20231127 end
                //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 end
            }

            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190912 start
            //点击确认关闭并触发校验方法
            $scope.citicTipClose = function() {
                modal('close', 'zhongxinModelOnChargeRefund', 'overwindowOnChargeRefund', 'zhongxinCloseX');
                toNextPage(true);
            };
            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190912 end

            //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 start
            $scope.ccbTipClose = function() {
                modal('close', 'ccbModelOnChargeRefund', 'overwindowOnChargeRefund');
                toNextPage(true);
            };
            //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 end
            
            //S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 start
            $scope.abcTipClose = function() {
                modal('close', 'abcModelOnChargeRefund', 'overwindowOnChargeRefund');
                toNextPage(true);
            };
            //S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 end 

            //查询签约接口成功回调
            function successCall(response) {
                myFactory.loadingHide();
                //查询是否签约的，未签约需要跳转到签约界面，并且传入相应参数
                var resCode = response.data.resultCode;
                agreePayCompanyCode = response.data.paymentChannel;

                //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 start
                var billfreq; //缴费方式
                var nextamount = $scope.policy.nextamount01; //续期保费
                var paymentPeriodInfo = response.data.paymentPeriodInfo;
                if ('1' == paymentPeriodInfo.state) {
                    paymentTimes = paymentPeriodInfo.insPrem_PyF_Prd_Num; //缴费次数
                    paymentDeadline = paymentPeriodInfo.pyF_CODt; //缴费截止日
                    limitPer = paymentPeriodInfo.per_Amt_UpLm_Val; //单笔金额上限值
                    billfreq = paymentPeriodInfo.billfreq; //缴费方式  00、趸缴；01、年缴；02、半年缴；04、季缴；12、月缴 
                }

                //如果变更缴别，需要用变更后的缴别判断
                for (var i = 0; i < $scope.itemList.length; i++) {
                    if ($scope.itemList[i].itemId == '04') {
                        billfreq = $scope.itemList[i].billFreq;
                        nextamount = $scope.itemList[i].itemCalculate.newprem;
                        paymentTimes = myFactory.getInsPremPyfPrdNum(paymentTimes, paymentPeriodInfo.billfreq, $scope.itemList[i].billFreq);
                        break;
                    }
                }
                paymentDeadline = myFactory.getPaymentDeadline(paymentDeadline, billfreq);
                console.log("缴费方式:" + billfreq + ",缴费截止日" + paymentDeadline);

                var signFlag = false;
                var signData = response.data.signData;
                var fmtFactFeeTotal = pageData.fmtFactFeeTotal; //本次变更应缴金额
                nextamount = '00' == billfreq ? '0' : nextamount; //续期保费
                var maxMoney = myFactory.getMaxMoney(fmtFactFeeTotal, nextamount, limitPer);
                var maxSignMoney = myFactory.getSignMoney(maxMoney);
                currentAmount = maxMoney;
                //如果变更缴别，单笔授权金额的最低限制，应为“变更后每期保费与本次变更应缴保费对比，取较大值”
                for (var i = 0; i < $scope.itemList.length; i++) {
                    if ($scope.itemList[i].itemId == '04') {
                        currentAmount = myFactory.getMaxMoney(fmtFactFeeTotal, nextamount, 0);
                    }
                }

                //如账号为已签约，如变更后的金额大于原授权金额，则要进入签约页面，允许修改授权金额；
                if ((resCode === 'R01' || resCode === 'R06') && bankCode == '04') {
                    //如账号为已签约，如变更后的缴费期数大于原授权次数、如变更后的金额大于原授权金额、如缴费方式为趸交，则要进入签约页面
                    //本次变更金额和P086返回的金额取较大值 * 1.2倍向上取整
                    if (parseInt(paymentTimes) > parseInt(signData.insPremPyfPrdNum) || parseFloat(maxSignMoney) > parseFloat(signData.sigleLimitAmount) ||
                        '00' == billfreq || myFactory.comparePayDate(paymentDeadline, signData.pyfCodt)) {
                        signFlag = true;
                        sigleLimitAmount = myFactory.getMaxMoney(maxSignMoney, maxSignMoney, signData.sigleLimitAmount);
                        paymentTimes = myFactory.getMaxInsPremPyfPrdNum(paymentTimes, signData.insPremPyfPrdNum);
                        paymentDeadline = myFactory.comparePayDate(paymentDeadline, signData.pyfCodt) ? paymentDeadline : signData.pyfCodt;
                    }
                } else if (resCode === 'R07') {
                    signFlag = true;
                    if (bankCode == '04') {
                        sigleLimitAmount = maxSignMoney;
                    }
                }

                if (!signFlag && (resCode === 'R05' || resCode === 'R06')) { //直连银行，无需签约 || 已签约
                    //	                	var isLimit =  checkbanklimit();
                    //	                	if ( isLimit ) {
                    //	                		 myFactory.alert("","缴费金额超出银行转账限额，请您选择其它银行账户","info");
                    //		                     return;
                    //	                	}
                    //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190912 start
                    //var signData = response.data.signData;
                    //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 end

                    var isDoSignature = signData.isDoSignature; //签名标志
                    if (resCode == 'R06' && isDoSignature == 'N') {
                        //合同文件初始化
                        var nowDate = new Date();
                        var nowYear = nowDate.getFullYear(); //当前年
                        var nowMonth = nowDate.getMonth() + 1; //当前月
                        nowMonth = nowMonth < 10 ? '0' + nowMonth : nowMonth;
                        var nowDay = nowDate.getDate() < 10 ? '0' + nowDate.getDate() : nowDate.getDate(); //当前日
                        var nowHour = nowDate.getHours() < 10 ? '0' + nowDate.getHours() : nowDate.getHours(); //当前时
                        var nowSeonds = nowDate.getMinutes() < 10 ? '0' + nowDate.getMinutes() : nowDate.getMinutes(); //当前分
                        var nowMilliseconds = nowDate.getSeconds() < 10 ? '0' + nowDate.getSeconds() : nowDate.getSeconds(); //当前秒
                        var deadlineStartTime = nowYear + '-' + nowMonth + '-' + nowDate.getDate(); //授权期限
                        var deadlineEndTime = '2099-12-31'; //授权期限
                        
                        /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010329 start*/
                        var signSuccessTime = signData.signSuccessTime;//签约成功时间(YYYY-MM-DD hh:ss:mm)
                        var signYear = signSuccessTime.substring(0,4);
                        var signMonth = signSuccessTime.substring(5,7);
                        var signDay = signSuccessTime.substring(8,10);
                        /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010329 end*/

                        var openBankName = bankNames; //开户行
                        if (bankNames.indexOf('(') > 0) {
                            openBankName = bankNames.substring(0, bankNames.indexOf("("));
                        }

                        var birthday = $scope.policyData.rnBirthday + "";
                        var tempdate = birthday.substr(0, 4) + "-" + birthday.substr(4, 2) + "-" + birthday.substr(6, 2);
                        var age = getAge(tempdate);
                        var bankAccountName = signData.accountName;
                        if (age < 18) {
                            bankAccountName = $scope.policyData.surname + "";
                        }

                        for (var i = 0; i < $scope.idTypeLF.length; i++) {
                            if ($scope.idTypeLF[i].contractVal === signData.cardIdType) {
                                idTypeName = $scope.idTypeLF[i].text; //证件类型名称
                                break;
                            }
                        }

                        for (var i = 0; i < bankinfomations.length; i++) {
                            //判断当机构和银行编码一致时使用，最佳
                            if (signData.bankCode == bankinfomations[i].reqBankCode) {
                                openBankName = bankinfomations[i].bankName;
                                break;
                            }
                        }

                        $scope.contractZxInfo = {
                            accountName: signData.accountName, //账户名
                            accountNum: signData.accountNo, //账户号
                            idType: signData.cardIdType, //证件类型
                            idNum: signData.cardId, //证件号码*/
                            openBankName: openBankName, //开户行
                            idTypeName: idTypeName, //证件类型名称
                            sigleLimitAmount: signData.sigleLimitAmount, //付款单笔限额
                            dayLimitAmount: signData.dayLimitAmount, //付款日累计限额
                            monthLimitAmount: signData.monthLimitAmount, //付款月累计限额
                            deadlineStartTime: deadlineStartTime, //授权期限
                            deadlineEndTime: deadlineEndTime, //授权期限
                            nowYear: nowYear, //当前年
                            nowMonth: nowMonth, //当前月
                            nowDay: nowDay, //当前日
                            nowHour: nowHour, //当前时
                            nowSeonds: nowSeonds, //当前分
                            nowMilliseconds: nowMilliseconds, //当前秒
                            /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010329 start*/
                            signYear : signYear,
                            signMonth : signMonth,
                            signDay : signDay,
                            /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010329 end*/
                            //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 start
                            bankAccountName: bankAccountName, //授权人签名
                            resultSign: resCode, //签约查询返回码
                            authorizedAmt: signData.signTotalMoney, //授权金额
                            paymentDeadline: signData.pyfCodt, //缴费截止日期
                            paymentTimes: signData.insPremPyfPrdNum, //缴费次数
                            //limitPer:signData.signTotalMoney//每期扣款限额
                            //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 end
                        };

                        //跳转
                        //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 start
                        if (signData.bankCode == '01' || signData.bankCode == '71') {
                            modal('open', 'zhongxinModelOnChargeRefund', 'overwindowOnChargeRefund', 'zhongxinCloseX');
                        } else if (signData.bankCode == '04') {
                            modal('open', 'ccbModelOnChargeRefund', 'overwindowOnChargeRefund');
                        }
                        //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 end
                        /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 start*/
                        /*S2022032221693-农业银行客户签约补充需求 add by huanghaokun 20220506 start*/
                        /*else if (signData.bankCode == '05'){
                        	modal('open', 'abcModelOnChargeRefund', 'overwindowOnChargeRefund');
                        }*/
                        /*S2022032221693-农业银行客户签约补充需求 add by huanghaokun 20220506 end*/
                        else{
                        	toNextPage(true);
                        }
                        /*S2021020516689-银行签约授权功能需求 add by huanghaokun 202010310 end*/
                    } else {
                        //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190912 end
                        toNextPage(true);
                        //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190912 start
                    }
                    //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190912 end
                    //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 start
                } else if (signFlag) {
                    //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 end
                    //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190912 start	

                    /*myFactory.alert("提示", "缴费银行未授权签约，请客户先在银行或我司官微办理授权签约手续后，再受理本次申请；或选择其它缴费银行。谢谢！","info");
	                	return;*/

                	//S2021020516689银行签约授权功能需求  add by huanghaokun 20210324 start
                	//被保险人为未成年人,授权人签名取投保人的名称
        			      var birthday = $scope.policyData.rnBirthday + "";
                    var tempdate = birthday.substr(0, 4) + "-" + birthday.substr(4, 2) + "-" + birthday.substr(6, 2);
                    var age = getAge(tempdate);
                    var bankAccountName = accountName;
                    if (age < 18) {
                        bankAccountName = $scope.policyData.surname + "";
                    }
                	//S2021020516689银行签约授权功能需求  add by huanghaokun 20210324 end
        			
                    //要签约，跳转到签约界面

                    //符合条件，跳转到查阅界面 
                    //封装、处理数据
                    var bankacctkey = $("#bankacctkey").val();
                    bankacctkey = bankacctkey.replace(/\s+/g, "");
                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start

                    /*移动保全问题反馈-保单选择退费账户为续期，却上传了其它银行卡影像件 add by huanghk 20221010 start*/
                    var accountFlag = $("#accountFlag").val().trim();
                    var bankCardItems = {
                        bankAccNum: bankacctkey,
                        accountFlag:accountFlag
                    }
                    if (accountFlag=="2" && $scope.bankCardNum == bankacctkey) {
                        bankCardItems['bigPic'] = $scope.bigPic;
                    }
                    /*移动保全问题反馈-保单选择退费账户为续期，却上传了其它银行卡影像件 add by huanghk 20221010 end*/
                    var timestamp = myFactory.getTimetamp();
                    var sfis = "token-timestamp";
                    var signStr = "token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                    var sign = myFactory.hex(signStr);
                    $http({
                        method: 'POST',
                        url: app.domain + 'img/saveBankCardCache.action',
                        data: { paramsMap: bankCardItems, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                    }).then(function successCallback(response) {
                        if (response.data.success) {
                            console.log("saveBankCardCache ok");
                        }
                    }, function errorCallback(response) {
                        console.log("saveIdCardCache error");
                    });

                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                    var nextAction = "charge_refund_preview";
                    var pageData2 = {
                        "accountFlag": $("#accountFlag").val().trim(),
                        "bankacctkey": bankacctkey,
                        "bankacctkey1": $("#bankacctkey1").val().trim(),
                        "bankacctkey3": $("#bankacctkey3").val().trim(),
                        "bankacctkeyCon": $("#bankacctkey").val().trim(), //不再采用需要输入第二次重复银行账户，用一个值就行了 BY ZZQ 2017/8/21
                        "bankcode": $("#newBankSelect option:selected").val().trim(),
                        "bankcode1": $("#bankcode1").val().trim(),
                        "bankcode3": $("#bankcode3").val().trim(),
                        "bankdesc": $("#newBankSelect option:selected").text().trim(),
                        "bankdesc1": $("#bankdesc1").val().trim(),
                        "bankdesc3": $("#bankdesc3").val().trim(),
                        "beneClntNum": beneClntNum,
                        "chargeType": chargeType,
                        "city": $("#newCityCode").val().trim(),
                        "city1": $("#city1").val().trim(),
                        "city3": $("#city3").val().trim(),
                        "citydesc": $("#newCity").val().trim(),
                        "citydesc1": $("#citydesc1").val().trim(),
                        "citydesc3": $("#citydesc3").val().trim(),
                        "itemIds": itemIds,
                        "paynme": $("#paynme").val().trim(),
                        "paynme1": $("#paynme1").val().trim(),
                        "paynme3": $("#paynme3").val().trim(),
                        "paynmeFlag": $("#paynmeFlag").val().trim(),
                        "paynum": $("#paynum").val().trim(),
                        "paynum1": $("#paynum1").val().trim(),
                        "paynum3": $("#paynum3").val().trim(),
                        "receiptAmount": ReceiptAmount,
                        "type": Type
                    }

                    $scope.pageData = $stateParams.pageData;
                    var items = {};
                    items['pageData2'] = pageData2;
                    items['pageData'] = $scope.pageData;
                    items['itemCommonList'] = itemCommonList;
                    items['strItemIds'] = strItemIds;
                    items['chdrnum01'] = chdrnum01;
                    items['chdrcoy'] = chdrcoy;
                    myFactory.loadingHide();
                    var contractItem = {
                        itemId: itemId,
                        userName: accountName,
                        accountType: accountType,
                        Bcode: code,
                        signMode: signMode,
                        isReal: '1',
                        branch: cntbranch,
                        idType: idType,
                        idNum: id,
                        accountNo: accountNo,
                        phoneNo: phoneNum,
                        BankName: bankNames,
                        BankCode: bankCode,
                        BankList: $scope.bankList,
                        nextAction: nextAction,
                        items: items,
                        flag: '2',
                        agreePayCompanyCode: agreePayCompanyCode,
                        sigleLimitAmount: sigleLimitAmount, //单日限额
                        dayLimitAmount: dayLimitAmount, //日累计限额
                        monthLimitAmount: monthLimitAmount, //月累计限额
                        //S2021020516689银行签约授权功能需求  add by huanghaokun 20210324 start
                		bankAccountName:bankAccountName,//授权人签名
                		//S2021020516689银行签约授权功能需求  add by huanghaokun 20210324 end
                        //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 start
                        dueDate: dueDate, //委托日期
                        resultSign: resCode, //签约查询返回码
                        authorizedAmt: authorizedAmt, //授权金额
                        paymentDeadline: paymentDeadline, //缴费截止日期
                        paymentTimes: paymentTimes, //缴费次数
                        currentAmount: currentAmount, //当前期缴保费
                        //limitPer:limitPer//每期扣款限额
                        //S2019112910966建设银行签约授权功能需求 add by yangyan 20200223 end
                        /*S2023011824901-官微授权银行页面超限额无拦截、非签约银行进入签约页面问题 add by huanghk 20230216 start*/
                        signMoney: pageData.fmtFactFeeTotal,
                        /*S2023011824901-官微授权银行页面超限额无拦截、非签约银行进入签约页面问题 add by huanghk 20230216 end*/

                    };
                    //S2021020516689银行签约授权功能需求  add by mqz 20210302 start
                    if( bankCode == '01' || bankCode == '71' || bankCode == '04') {
                    	$ionicHistory.clearCache().then(function() {
	                        $state.go('contract', { contractItem: contractItem });
	                    });
                    }else{
	                    $ionicHistory.clearCache().then(function() {
	                        $state.go('contract_other', { contractItem: contractItem });
	                    });
                    }
                    //S2021020516689银行签约授权功能需求  add by mqz 20210302 end
                    //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190912 end
                } else {
                    myFactory.alert("提示", response.data.resultMsg, "info");
                    return;
                }
            }

            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190910 start
            /*根据出生日期算出年龄*/
            function getAge(strBirthday) {
                var returnAge;
                var strBirthdayArr = strBirthday.split("-");
                var birthYear = strBirthdayArr[0];
                var birthMonth = strBirthdayArr[1];
                var birthDay = strBirthdayArr[2];

                d = new Date();
                var nowYear = d.getFullYear();
                var nowMonth = d.getMonth() + 1;
                var nowDay = d.getDate();

                if (nowYear == birthYear) {
                    returnAge = 0; //同年 则为0岁  
                } else {
                    var ageDiff = nowYear - birthYear; //年之差  
                    if (ageDiff > 0) {
                        if (nowMonth == birthMonth) {
                            var dayDiff = nowDay - birthDay; //日之差  
                            if (dayDiff < 0) {
                                returnAge = ageDiff - 1;
                            } else {
                                returnAge = ageDiff;
                            }
                        } else {
                            var monthDiff = nowMonth - birthMonth; //月之差  
                            if (monthDiff < 0) {
                                returnAge = ageDiff - 1;
                            } else {
                                returnAge = ageDiff;
                            }
                        }
                    } else {
                        returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天  
                    }
                }
                return returnAge; //返回周岁年龄  
            }
            //S2018062604412网联政策630实施相关系统功能改造需求(中信银行签约需求)_授权书赋值 by  CYQ  20190910 end

            //查询签约接口失败回调
            function errorCall() {
                myFactory.loadingHide();
                myFactory.alert("", "查询签约失败，请稍后重试", "info");
                return;
            }
            //	            //匹配銀行單日，月度限額等等信息
            function checkbanklimit(currentBankcode) {
                var bankinfo = null;
                console.log("当前保单所属的机构号：" + $scope.policyData.cntbranch);
                for (var i = 0; i < pclistBack.length; i++) {
                    if (currentBankcode == pclistBack[i].bankcode) {
                        bankinfo = pclistBack[i];
                        break;
                    }
                }
                if (null != bankinfo) {
                    sigleLimitAmount = bankinfo.sigleLimitAmount; //单日限额
                    dayLimitAmount = bankinfo.dayLimitAmount; //日累计限额
                    monthLimitAmount = bankinfo.monthLimitAmount; //月累计限额
                    dueDate = bankinfo.dueDate; //委托日期
                } else {
                    sigleLimitAmount = "500000"; //单日限额
                    dayLimitAmount = "500000"; //日累计限额
                    monthLimitAmount = "500000"; //月累计限额
                    dueDate = "20991229"; //委托日期
                }
            }
            //匹配银行是否签约以及银行限额信息
            function matchBankInfo() {
                for (var j = 0; j < pclist.length; j++) {
                    var item = pclist[j];
                    var isMate = true;
                    var a = {};
                    var temp = null;
                    for (var i = 0; i < bankinfomations.length; i++) {
                        //判断当机构和银行编码一致时使用，最佳
                        if (item.bankcode == bankinfomations[i].reqBankCode && cntbranch == bankinfomations[i].branch) {
                            if (bankinfomations[i].offlineNeedSign == 'Y') {
                                a.bankdesc = item.bankdesc + "(需要签约)";
                            } else {
                                a.bankdesc = item.bankdesc;
                            }
                            a.bankcode = item.bankcode;
                            a.limit = bankinfomations[i].batchLimitAmount
                            a.sigleLimitAmount = bankinfomations[i].sigleLimitAmount; //付款单笔限额
                            a.dayLimitAmount = bankinfomations[i].dayLimitAmount; //付款日累计限额
                            a.monthLimitAmount = bankinfomations[i].monthLimitAmount; //付款月累计限额
                            a.dueDate = bankinfomations[i].dueDate; //委托日期
                            isMate = true;
                            break;
                        } else {
                            isMate = false;
                        }
                        if (item.bankcode == bankinfomations[i].reqBankCode && bankinfomations[i].branch == 'ALL') {
                            temp = bankinfomations[i];
                        }
                    }
                    if (!isMate && temp != null) {
                        if (temp.offlineNeedSign == 'Y') {
                            a.bankdesc = item.bankdesc + "(需要签约)";
                        } else {
                            a.bankdesc = item.bankdesc;
                        }
                        a.bankcode = item.bankcode;
                        a.limit = temp.batchLimitAmount
                        a.sigleLimitAmount = temp.sigleLimitAmount; //付款单笔限额
                        a.dayLimitAmount = temp.dayLimitAmount; //付款日累计限额
                        a.monthLimitAmount = temp.monthLimitAmount; //付款月累计限额
                        a.dueDate = temp.dueDate; //委托日期
                        isMate = true;
                    }
                    if (!isMate) { //没有匹配到银行信息，则默认不需要签约
                        a.bankdesc = item.bankdesc;
                        a.bankcode = item.bankcode;
                        a.limit = ""; //默认没有限额
                        a.sigleLimitAmount = "500000"; //付款单笔限额
                        a.dayLimitAmount = "500000"; //付款日累计限额
                        a.monthLimitAmount = "500000"; //付款月累计限额
                        a.dueDate = "20991231"; //委托日期
                    }
                    pclistBack.push(a);
                }
            }
            /**
             * S2018062604412网联政策630实施相关系统功能改造需求（移动保全2.0增加签约功能）
             * 新增签约接口的逻辑 add by csf 20180926 end
             * 
             */
        }]);

    //保单详情弹窗
    app.directive('infoid', function() {
        return {
            restrict: 'EA', //指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
            templateUrl: 'html/input/content_base_info.html' + app.clearCache,
            replace: true, //设置解析后，DOM声明的指令是否消失
            link: function(scope, element, attrs) { //链接函数负责注册DOM事件和更新DOM,
                console.log('弹框指令完成');
            }
        }
    });
})(app)